using System;

namespace SharpMud.Net.Telnet.MXP
{
	public class ElementDefinition : IElementDefinition
	{
		#region Private Variables
		private string							_ElementName;
		private string							_ElementDefinition;
		private System.Collections.ArrayList	_AttributeList;
		private bool							_IsOpenTag;
		private bool							_IsEmptyTag;
		private bool							_IsDefinitionDeletion;
		#endregion

		#region Constructors
		public ElementDefinition()
		{
		}
		public ElementDefinition(string elementName, bool isOpenTag, bool isEmptyTag, bool isDefinitionDeletion)
			:this(elementName,String.Empty,new IAttributeDefinition[] {}, isOpenTag, isEmptyTag, isDefinitionDeletion)
		{
		}
		public ElementDefinition(string elementName, string elementDefinition, bool isOpenTag, bool isEmptyTag, bool isDefinitionDeletion)
			:this(elementName,String.Empty,new IAttributeDefinition[] {}, isOpenTag, isEmptyTag, isDefinitionDeletion)
		{
		}
//		public ElementDefinition(string elementName, string elementDefinition, IAttributeDefinition[] attributeList, bool isOpenTag, bool isEmptyTag, bool isDefinitionDeletion)
//			:this(elementName,elementDefinition,new IAttributeDefinition[] {}, isOpenTag, isEmptyTag, isDefinitionDeletion)
//		{
//		}
		public ElementDefinition(string elementName, string elementDefinition, IAttributeDefinition[] attributeList, bool isOpenTag, bool isEmptyTag, bool isDefinitionDeletion)
		{
			_ElementName = elementName;
			_ElementDefinition = elementDefinition;
			_AttributeList = new System.Collections.ArrayList(); _AttributeList.AddRange(attributeList);
			_IsOpenTag = isOpenTag;
			_IsEmptyTag = isEmptyTag;
			_IsDefinitionDeletion = isDefinitionDeletion;
		}
		#endregion

		#region Public Properties

		#endregion

		#region Public Methods
		public string ToString()
		{
			System.Text.StringBuilder sb = new System.Text.StringBuilder();
			sb.Append("<!ELEMENT ");
			sb.Append(((IElementDefinition)this).ElementName.Trim() + " ");
			if(((IElementDefinition)this).Definition!=String.Empty && ((IElementDefinition)this).Definition!=null)
			{
				sb.Append("'" + ((IElementDefinition)this).Definition + "' ");
			}
			if(((IElementDefinition)this).Attributes.Length>0)
			{
				sb.Append("ATT='");
				foreach(IAttributeDefinition ad in ((IElementDefinition)this).Attributes)
				{
					sb.Append(ad.Name.Trim());
					if(ad.DefaultValue!=null && ad.DefaultValue!=String.Empty)
					{
						sb.Append("=");
						sb.Append(ad.DefaultValue.Trim());
					}
					sb.Append(" ");
				}
				sb.Remove(sb.Length-1,1);
				sb.Append("' ");
			}
			if(((IElementDefinition)this).Open)
			{
				sb.Append("OPEN ");
			}
			if(((IElementDefinition)this).Delete)
			{
				sb.Append("DELETE ");
			}
			if(((IElementDefinition)this).Empty)
			{
				sb.Append("EMPTY ");
			}
			sb.Append(">");

			return sb.ToString();
		}
		#endregion

		#region IElementDefinition Members

		string IElementDefinition.ElementName
		{
			get
			{
				return this._ElementName;
			}
		}

		string IElementDefinition.Definition
		{
			get
			{
				return this._ElementDefinition;
			}
		}

		IAttributeDefinition[] IElementDefinition.Attributes
		{
			get
			{
				return (IAttributeDefinition[])this._AttributeList.ToArray(typeof(IAttributeDefinition));
			}
		}

		bool IElementDefinition.Open
		{
			get
			{
				return this._IsOpenTag;
			}
		}

		bool IElementDefinition.Delete
		{
			get
			{
				return this._IsDefinitionDeletion;
			}
		}

		bool IElementDefinition.Empty
		{
			get
			{
				return this._IsEmptyTag;
			}
		}

		string IElementDefinition.ToString()
		{
			return this.ToString();
		}

		#endregion
	}

}
